<!--

    Copyright © 2016-2024 The Thingsboard Authors

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<div class="tb-form-panel no-padding no-border" [formGroup]="appearanceFormGroup">
  <tb-image-cards-select rowHeight="3:1"
                         [cols]="{columns:  2,
                                    breakpoints: {
                                      'lt-sm': 1
                                    }}"
                         label="{{ 'widgets.button.layout' | translate }}" formControlName="type">
    <tb-image-cards-select-option *ngFor="let type of widgetButtonTypes"
                                  [value]="type"
                                  [image]="widgetButtonTypeImageMap.get(type)">
      {{ widgetButtonTypeTranslationMap.get(type) | translate }}
    </tb-image-cards-select-option>
  </tb-image-cards-select>
  <div *ngIf="withAutoScale" class="tb-form-row">
    <mat-slide-toggle class="mat-slide" formControlName="autoScale">
      {{ 'widgets.button.auto-scale' | translate }}
    </mat-slide-toggle>
  </div>
  <div class="tb-form-row">
    <mat-slide-toggle class="mat-slide fixed-title-width" formControlName="showLabel">
      {{ 'widgets.button.label' | translate }}
    </mat-slide-toggle>
    <mat-form-field class="flex" appearance="outline" subscriptSizing="dynamic">
      <input matInput formControlName="label" placeholder="{{ 'widget-config.set' | translate }}">
    </mat-form-field>
  </div>
  <div class="tb-form-row">
    <mat-slide-toggle class="mat-slide fixed-title-width" formControlName="showIcon">
      {{ 'widgets.button.icon' | translate }}
    </mat-slide-toggle>
    <div fxFlex fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px">
      <mat-form-field appearance="outline" class="flex number" subscriptSizing="dynamic">
        <input matInput type="number" min="0" formControlName="iconSize" placeholder="{{ 'widget-config.set' | translate }}">
      </mat-form-field>
      <tb-css-unit-select fxFlex formControlName="iconSizeUnit"></tb-css-unit-select>
      <tb-material-icon-select asBoxInput
                               iconClearButton
                               formControlName="icon">
      </tb-material-icon-select>
    </div>
  </div>
  <div *ngIf="withBorderRadius" class="tb-form-row">
    <div class="fixed-title-width">{{ 'widgets.button.border-radius' | translate }}</div>
    <tb-css-size-input flex formControlName="borderRadius"></tb-css-size-input>
  </div>
  <div class="tb-form-row space-between column-xs">
    <div>{{ 'widgets.button.color-palette' | translate }}</div>
    <div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="12px">
      <div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px">
        <div translate>widgets.button.main</div>
        <tb-color-input asBoxInput
                        formControlName="mainColor">
        </tb-color-input>
      </div>
      <mat-divider vertical></mat-divider>
      <div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px">
        <div translate>widgets.button.background</div>
        <tb-color-input asBoxInput
                        formControlName="backgroundColor">
        </tb-color-input>
      </div>
    </div>
  </div>
  <div class="tb-form-panel stroked" formGroupName="customStyle">
    <mat-expansion-panel class="tb-settings">
      <mat-expansion-panel-header fxLayout="row wrap">
        <mat-panel-title>
          <div class="tb-form-panel-title" translate>widgets.button.custom-styles</div>
        </mat-panel-title>
      </mat-expansion-panel-header>
      <ng-template matExpansionPanelContent>
        <div class="tb-form-row space-between" *ngFor="let state of widgetButtonStates">
          <div>{{ widgetButtonStateTranslationMap.get(state) | translate }}</div>
          <tb-widget-button-custom-style
            [state]="state"
            [appearance]="this.appearanceFormGroup.value"
            [borderRadius]="borderRadius"
            [autoScale]="autoScale"
            [formControlName]="state">
          </tb-widget-button-custom-style>
        </div>
      </ng-template>
    </mat-expansion-panel>
  </div>
</div>
